<?php
include "head_lv2.php";
if($_GET['ibarcode']&&$_GET['icount']&&$_GET['s_no']){
	$barcode = $_GET['ibarcode'];
	$count = $_GET['icount'];
	if($_GET['s_no']){
		$s_no = $_GET['s_no'];
	}else{
		OnlyMsgView("점포부터 선택해 주세요.");
		return;
	}
	$sear_char .= " and barcode = '$barcode' ";
	
	$query = "SELECT uatp_shopinfo.name AS 'shopname', uatp_product.no AS 'p_no', uatp_product.barcode, uatp_product.unit,
												uatp_product.productname, uatp_product.price1, 
												uatp_stock.count FROM uatp_stock 
												INNER JOIN uatp_shopinfo ON uatp_stock.s_no = uatp_shopinfo.no 
												INNER JOIN uatp_product ON uatp_stock.p_no = uatp_product.no 
												WHERE uatp_stock.s_no = $s_no $sear_char order by p_no DESC LIMIT 0, 100";
	$total = DBnumrows($query);
	$list = DBarray($query);
	if($total==""){
		OnlyMsgView('바코드와 일치하는 상품이 존재하지 않습니다.');
			return;
	}
	$gap = $count - $list['count'];
	
	if($gap>0){
		$gap_view = "<font color='blue'>".$gap."&nbsp;".$list['unit']."</font>";
	}
	else if($gap<0){
		$gap_view = "<font color='#B4045F'>".$gap."&nbsp;".$list['unit']."</font>";
	}
	else{
		$gap_view = "정상";
	}
	
	echo "<tr>
	<input type='hidden' name='p_no[]' value='".$list['p_no']."'/>
	<input type='hidden' name='barcode[]' value='".$barcode."'/>
	<input type='hidden' name='count[]' value='".$count."'/>
	<input type='hidden' name='gap[]' value='".$gap."'/>
			<td style='width:150px;'>".$barcode."</td>
			<td style='width:300px;'>".$list['productname']."</td>
			<td style='text-align:right;'>".$list['count']."&nbsp;".$list['unit']."</td>
			<td style='width:70px;text-align:right;'>".$count."&nbsp;".$list['unit']."</td>
			<td style='text-align:right;'>".$gap_view."</td>
			<td onclick='deleteRow(this);' style='cursor:pointer;text-align:center'>삭제</td>
			</tr>";
	return;
}

if($b_no = $_GET['b_no']){
	$query = "select * from uatp_middlecategory where b_no='$b_no';";
	$result = DBquery($query);
	while($row = mysql_fetch_array($result)){
		$total .= "<option value=$row[no]>$row[name]</option>";
	}
	echo $total;
}

if($sg_no = $_GET['sg_no']){
	$query = "select * from uatp_shopinfo where sg_no='$sg_no';";
	$result = DBquery($query);
	$total = "<option value='0'>:: 점포 선택 ::</option>";
	while($row = mysql_fetch_array($result)){
		$total .= "<option value=$row[no]>$row[name]</option>";
	}
	echo $total;
}

if($s_no = $_GET['s_no']){
	$query = "select * from uatp_staff where s_no='$s_no';";
	$result = DBquery($query);
	$total = "<option value='0'>:: 담당자 선택 ::</option>";
	while($row = mysql_fetch_array($result)){
		$total .= "<option value=$row[no]>$row[name]</option>";
	}
	echo $total;
}
?>